<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>替换页面元素</title>
    <script>
        function replaceNode() {
            var parentDiv = document.getElementById('parentDiv');
                      
          var secondP = parentDiv.children[1]; 
                     
            var newDiv = document.createElement('div');
                     
            var textNode = document.createTextNode('JavaScript课程');
                    
            newDiv.appendChild(textNode);
            
                      parentDiv.replaceChild(newDiv, secondP);
        }
        </script>
</head>
<body>
    
<div id="parentDiv">
    <p>我是第一行内容</p>
    <p>我是第二行内容</p> 
    <p>我是第三行内容</p>
    <p>我是第四行内容</p>
</div>

<button onclick="replaceNode()">将第2行内容替换为JavaScript课程</button>

</body>
</html>